﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>SignalR Simple Chat</title>
    <style type="text/css">
        .container {
            background-color: #99CCFF;
            border: thick solid #808080;
            padding: 20px;
            margin: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <input type="text" id="message" />
        <input type="button" id="sendmessage" value="Send" />
        <input type="hidden" id="displayname" />
        <ul id="discussion"></ul>
    </div>
    <!--Script references. -->
    <!--Reference the jQuery library. -->
    <script src="Scripts/jquery-1.6.4.min.js"></script>
    <!--Reference the SignalR library. -->
    <script src="Scripts/jquery.signalR-2.2.0.min.js"></script>
    <!--Add script to update the page and send messages.-->
    <script type="text/javascript">
        $(function () {
            // Get the user name and store it to prepend to messages.
            $('#displayname').val(prompt('Enter your name:', ''));
            // Set initial focus to message input box.
            $('#message').focus();
            // Declare a proxy to reference the hub.
            //var chat = $.connection.chatHub;
            var connection = $.connection("/IoT");
            connection.logging = true;//启用Console日志
            connection.start().done(function () {
                $('#sendmessage').click(function () {
                    // Call the Send method on the hub.
                    connection.send($('#displayname').val(), $('#message').val());
                    // Clear text box and reset focus for next comment.
                    $('#message').val('').focus();
                });
                //alert("start done");
            });
            connection.start().done(function () {
                $('#sendmessage').click(function () {
                    // Call the Send method on the hub.
                    connection.send($('#displayname').val(), $('#message').val());
                    // Clear text box and reset focus for next comment.
                    $('#message').val('').focus();
                });
                alert("start done");
            });
            connection.error(function (err) {
                alert("Error:"+err.message);
            });
            connection.received(function (msg) {
                $('#discussion').append('<li><strong>System</strong>:&nbsp;&nbsp;' + msg + '</li>');
            });
            connection.start();
        });
    </script>
</body>
</html>
